from django.shortcuts import render_to_response
from google.appengine.ext import db
from models.models import Users, Categories, Articles, Article_rel_Category
from utils.users_util import getusername

def list(request,category='home'):
	categories=db.GqlQuery('SELECT * FROM Categories WHERE isActive=True ORDER BY priority')
	return render_to_response('blog/list.html',{'categories':categories,'currcategory':category,'username':getusername(request)})

def article(request,article):
	category='home'
	categories=db.GqlQuery('SELECT * FROM Categories WHERE isActive=True ORDER BY priority')
	return render_to_response('blog/article.html',{'categories':categories,'currcategory':category, 'username':getusername(request)})

def mypost(request):
	category='java'
	categories=db.GqlQuery('SELECT * FROM Categories WHERE isActive=True ORDER BY priority')
	return render_to_response('blog/article.html',{'categories':categories,'currcategory':category, 'username':getusername(request)})

def init_categories():
	categories=[
		{'name':'home','title':'Home','priority':10,'isActive':True},
		{'name':'java','title':'Java','priority':20,'isActive':True},
		{'name':'python','title':'Python','priority':30,'isActive':True},
		{'name':'music','title':'Music','priority':40,'isActive':True},
		{'name':'film','title':'Film','priority':50,'isActive':True},
		{'name':'language','title':'Language','priority':60,'isActive':True},
		{'name':'logic','title':'Logic','priority':70,'isActive':True},
		{'name':'philosophy','title':'Philosophy','priority':80,'isActive':True},
		{'name':'game','title':'Game','priority':90,'isActive':True}
	]
	for category in categories:
		ca=Categories(name=category['name'],title=category['title'],priority=category['priority'],isActive=category['isActive'])
		ca.save()